<%@ include file="/WEB-INF/template/include.jsp"%>
<%@ include file="localHeader.jsp"%>
<%@ page import="java.util.*,java.text.*" %>

<openmrs:htmlInclude file="/scripts/calendar/calendar.js" />
<openmrs:htmlInclude file="/scripts/jquery/jquery-1.3.2.min.js" />
<openmrs:require privilege="View Orders" otherwise="/login.htm" redirect="/module/simplelabentry/workList.htm" />

<br/>

<form id="workList" method="get" action="workList.htm">
    <input type="hidden" name="action" value="render"/>
    <b class="boxHeader">Step 1. Choose which results you want to enter:</b>
    <div class="box">
        <br>
        <table>
            <tr>

            </tr>
            <tr>
                <td>
                    <label class="desc" for="orderDate">Date</label>
                </td>
                <td>
                    <input type="text" id="orderDate" name="orderDate" size="10" value="<c:if test="${!empty param.orderDate}">${param.orderDate}</c:if><c:if test="${empty param.orderDate}">${todayStr}</c:if>" onFocus="showCalendar(this)" />
                </td>
                <td>
                    Select Lab:
                </td>
                <td>
                    <select name="labName" id="labName">
                        <option id="select">Select</option>
                        <c:forEach items="${headingList}" var="tabHeading">

                            <openmrs:hasPrivilege privilege="View ${tabHeading.name}">
                                <option id="${tabHeading.name}" name="${tabHeading.name}" value="${tabHeading.name}" <c:if test="${!empty param.labName && param.labName == tabHeading.name}">selected="selected"</c:if>><spring:message code="${tabHeading.name}"/></option>
                            </openmrs:hasPrivilege>
                        </c:forEach>
                    </select>
                </td>

                <td>
                    <input type="button" name="workList" id="workList" value="Get Work List" onClick="submitForm()"/>
                </td>
                <c:forEach items="${headingList}" var="tabHeading">
                <c:if test="${!empty param.labName && param.labName == tabHeading.name && param.labName != 'Select'}">
                    <td>
			Filter by Test:
                    </td>
                    <td colspan="4">
                        <select name="groupKey" id="groupKey" onChange="this.form.submit()">
                        <option id="select" value="Select" selected="selected">Select</option>
                            <c:forEach items="${tabHeading.answers}" var="conceptAns">
                                <option name="${conceptAns.answerConcept.id}" value="${conceptAns.answerConcept.name}" <c:if test="${!empty param.groupKey && param.groupKey == conceptAns.answerConcept.name}">selected="selected"</c:if>><spring:message code="${conceptAns.answerConcept.name}"/></option>
                            </c:forEach>
                        </select>
                    </td>
                </c:if>
            </c:forEach>

            </tr>
        </table>

    </div>
</form>

<br/>
<c:if test="${!empty param.orderDate || !empty param.labName && param.labName != 'Select'}">

    <openmrs:portlet url="enterResult"
        id="orderEntrySectionId"
        moduleId="simplelabentry"
        parameters="workList=true|confidentialTest=false|limit=open|groupKey=${param.labName}|orderDate=${param.orderDate}" />
</c:if>

<script type="text/javascript">
    function submitForm(){
	var orderDate = document.getElementById('orderDate').value;

        if(orderDate==null || orderDate=="")
        {
            alert("Please enter Order Date");
        }
        else if(!dateISO(orderDate))
        {
            alert("Please enter valid Order Date");
                document.getElementById('orderDate').value = "";
        }
        else if(document.getElementById('labName').value=="Select")
        {
            alert("Please Select Lab Name");
        }
        else
        {
            document.getElementById('workList').submit();
        }
}

   function dateISO(value) {
        return /^\d{2}[\/-]\d{2}[\/-]\d{4}$/i.test(value);
    }

</script>

<%@ include file="/WEB-INF/template/footer.jsp"%>
